package com.mes.task.domain;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.JoinColumnOrFormula;
import org.hibernate.annotations.JoinColumnsOrFormulas;
import org.hibernate.annotations.JoinFormula;
import org.springframework.context.annotation.Lazy;

import com.mes.basicdata.domain.Dept;
import com.mes.basicdata.domain.Part;
import com.mes.basicdata.domain.TypesData;
import com.mes.common.domain.BasicModel;
/**
 * author lcs
 * data 2017-03-19
**/
@Entity()
@org.hibernate.annotations.Entity(dynamicInsert=true,dynamicUpdate=true)
@Table(name = "T_MDS")
@BatchSize(size=20)
@Lazy(value=true)
//省略SQL语句：where=" mdstype like '0%'"
//@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Mds extends BasicModel {

	private static final long serialVersionUID = 7086417044107768445L;
	
	@Transient
	public final static int MDSSTATE_DRAFT= 0; //草稿
	@Transient
	public final static int MDSSTATE_STARTED = 1; //生效
	@Transient
	public final static int MDSSTATE_FINISHED = 2; //已结案
	
	@Id
	@GenericGenerator(name = "mdsId", strategy = "assigned")
	@Column(name="MDSID")
	protected String mdsId;
	
	@Override
	public String getUuid() {
		return mdsId;
	}

	@Override
	public void setUuid(String uuid) {
		this.mdsId = uuid;
	}
	
	@Column(name="PART_NUMBER")
	protected String partUid;
	/**
	 * 复杂对象映射--part
	 */
	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="PART_NUMBER",insertable=false,updatable=false)
	protected Part part;
	
	@Column(name="DUEQTY", precision=25, scale=6)
	protected Double dueQty;
	
	@Column(name="EARLYSTART",length=7)
	protected Date earlyStart;
	
	@Column(name="EARLYFINISH",length=7)
	protected Date earlyFinish;
	
	@Column(name="LATESTART",length=7)
	protected Date lateStart;
	
	@Column(name="LATEFINISH",length=7)
	protected Date lateFinish;
	
	@Column(name="ACTUALSTART",length=7)
	protected Date actualStart;
	
	@Column(name="ACTUALFINISH",length=7)
	protected Date actualFinish;
	
	/**
	 * 类型与状态映射--priority
	 */
	@Column(name="PRIORITY")
	protected Long priority;
	
	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumnsOrFormulas(value={
			@JoinColumnOrFormula(column=@JoinColumn(name="PRIORITY",referencedColumnName="ID",nullable=true,insertable=false,updatable=false)),
			@JoinColumnOrFormula(formula=@JoinFormula(value="'mdsPrio'", referencedColumnName="TYPESNAME"))
	})
	protected TypesData priorityDesc;
	
	@Column(name="COMPLETEPERCENT", precision=25, scale=6 )
	protected Double completePercent;

	/**
	 * 类型与状态映射--mdsType
	 */
	@Column(name="MDSTYPE",length=50)
	protected String mdsType;
	
	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumnsOrFormulas(value={
			@JoinColumnOrFormula(column=@JoinColumn(name="MDSTYPE",referencedColumnName="ID",nullable=true,insertable=false,updatable=false)),
			@JoinColumnOrFormula(formula=@JoinFormula(value="'mdstype'", referencedColumnName="TYPESNAME"))
	})
	protected TypesData  mdsTypeDesc;
	
	/**
	 * 类型与状态映射--mdsstate
	 */
	@Column(name="MDSSTATE", precision=20, scale=6 )
	protected Long mdsState;
	
	//暂时注释lcs，添加有错误
/*	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumnsOrFormulas(value={
			@JoinColumnOrFormula(formula=@JoinFormula(value="'to_char(MDSSTATE)'", referencedColumnName="TYPESNAME")),
			@JoinColumnOrFormula(formula=@JoinFormula(value="'mdsstate'", referencedColumnName="TYPESNAME"))
	})
	protected TypesData mdsStateDesc;*/
	
	@Column(name="DELIVERYQTY", precision=25, scale=6 )
	protected Double deliveryQty;
	@Column(name="DEPTID")
	protected String deptUid;
	/**
	 * 复杂对象映射--dept
	 */
	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="DEPTID",insertable=false,updatable=false)
	protected Dept dept;
	
	@Column(name="MASTERSHOP")
	protected String masterShopUid;
	/**
	 * 复杂对象映射--mastershop
	 */
	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="MASTERSHOP",referencedColumnName="DEPTID",insertable=false,updatable=false)
	protected Dept masterShop;
	
	@Column(name="ISBREAK")
	protected Boolean isBreak;
	
	@Column(name="XBOMUID")
	protected String xbomUid;
	/**
	 * 复杂对象映射--xbom
	 */
	//暂时注释lcs，添加有错误
/*	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="UUID",referencedColumnName="UUID",insertable=false,updatable=false)
	protected Xbom xbom;*/
	
	public Mds(){
		super();
		this.setMdsType("0");
	}

	public String getMdsId() {
		return mdsId;
	}

	public void setMdsId(String mdsId) {
		this.mdsId = mdsId;
	}

	public String getPartUid() {
		return partUid;
	}

	public void setPartUid(String partUid) {
		this.partUid = partUid;
	}

	public Part getPart() {
		return part;
	}

	public void setPart(Part part) {
		this.part = part;
	}

	public Double getDueQty() {
		return dueQty;
	}

	public void setDueQty(Double dueQty) {
		this.dueQty = dueQty;
	}

	public Date getEarlyStart() {
		return earlyStart;
	}

	public void setEarlyStart(Date earlyStart) {
		this.earlyStart = earlyStart;
	}

	public Date getEarlyFinish() {
		return earlyFinish;
	}

	public void setEarlyFinish(Date earlyFinish) {
		this.earlyFinish = earlyFinish;
	}

	public Date getLateStart() {
		return lateStart;
	}

	public void setLateStart(Date lateStart) {
		this.lateStart = lateStart;
	}

	public Date getLateFinish() {
		return lateFinish;
	}

	public void setLateFinish(Date lateFinish) {
		this.lateFinish = lateFinish;
	}

	public Date getActualStart() {
		return actualStart;
	}

	public void setActualStart(Date actualStart) {
		this.actualStart = actualStart;
	}

	public Date getActualFinish() {
		return actualFinish;
	}

	public void setActualFinish(Date actualFinish) {
		this.actualFinish = actualFinish;
	}

	public Long getPriority() {
		return priority;
	}

	public void setPriority(Long priority) {
		this.priority = priority;
	}

	public TypesData getPriorityDesc() {
		return priorityDesc;
	}

	public void setPriorityDesc(TypesData priorityDesc) {
		this.priorityDesc = priorityDesc;
	}

	public Double getCompletePercent() {
		return completePercent;
	}

	public void setCompletePercent(Double completePercent) {
		this.completePercent = completePercent;
	}

	public String getMdsType() {
		return mdsType;
	}

	public void setMdsType(String mdsType) {
		this.mdsType = mdsType;
	}

	public TypesData getMdsTypeDesc() {
		return mdsTypeDesc;
	}

	public void setMdsTypeDesc(TypesData mdsTypeDesc) {
		this.mdsTypeDesc = mdsTypeDesc;
	}

	public Long getMdsState() {
		return mdsState;
	}

	public void setMdsState(Long mdsState) {
		this.mdsState = mdsState;
	}

/*	public TypesData getMdsStateDesc() {
		return mdsStateDesc;
	}

	public void setMdsStateDesc(TypesData mdsStateDesc) {
		this.mdsStateDesc = mdsStateDesc;
	}
*/
	public Double getDeliveryQty() {
		return deliveryQty;
	}

	public void setDeliveryQty(Double deliveryQty) {
		this.deliveryQty = deliveryQty;
	}

	public String getDeptUid() {
		return deptUid;
	}

	public void setDeptUid(String deptUid) {
		this.deptUid = deptUid;
	}

	public Dept getDept() {
		return dept;
	}

	public void setDept(Dept dept) {
		this.dept = dept;
	}

	public String getMasterShopUid() {
		return masterShopUid;
	}

	public void setMasterShopUid(String masterShopUid) {
		this.masterShopUid = masterShopUid;
	}

	public Dept getMasterShop() {
		return masterShop;
	}

	public void setMasterShop(Dept masterShop) {
		this.masterShop = masterShop;
	}

	public Boolean getIsBreak() {
		return isBreak;
	}

	public void setIsBreak(Boolean isBreak) {
		this.isBreak = isBreak;
	}

	public String getXbomUid() {
		return xbomUid;
	}

	public void setXbomUid(String xbomUid) {
		this.xbomUid = xbomUid;
	}

/*	public Xbom getXbom() {
		return xbom;
	}

	public void setXbom(Xbom xbom) {
		this.xbom = xbom;
	}*/
}
